<?php
require_once 'vendor/autoload.php';

// 初始化应用
$app = new \think\App();
$app->initialize();

use app\model\Order;

try {
    echo "直接测试订单数据...\n";
    
    // 直接调用Order模型的getOrderList方法
    $result = Order::getOrderList([
        'page' => 1,
        'limit' => 10,
        'shop_name' => '',
        'order_status' => '',
        'start_date' => '',
        'end_date' => ''
    ]);
    
    echo "总订单数: " . $result['total'] . "\n";
    echo "当前页订单数: " . count($result['list']) . "\n";
    
    if (!empty($result['list'])) {
        echo "\n前5个订单的详细信息:\n";
        for ($i = 0; $i < min(5, count($result['list'])); $i++) {
            $order = $result['list'][$i];
            echo "\n订单 " . ($i + 1) . ":\n";
            echo "- 订单号: " . ($order['order_no'] ?? 'N/A') . "\n";
            echo "- 店铺名称: " . ($order['shop_name'] ?? 'N/A') . "\n";
            echo "- 商品ID: " . ($order['goods_id'] ?? 'N/A') . "\n";
            echo "- 商品名称: " . ($order['product_name'] ?? 'N/A') . "\n";
            echo "- 订单状态: " . ($order['order_status_str'] ?? 'N/A') . "\n";
            echo "- 下单时间: " . ($order['order_date'] ?? 'N/A') . "\n";
            echo "- 运费: " . ($order['post_amount'] ?? 'N/A') . "\n";
            echo "- 服务费: " . ($order['commission_price'] ?? 'N/A') . "\n";
            echo "- 预收款金额: " . ($order['total_amount'] ?? 'N/A') . "\n";
            echo "- 实际收款金额: " . ($order['pay_amount'] ?? 'N/A') . "\n";
            echo "- 外部订单号: " . ($order['parent_order_id'] ?? 'N/A') . "\n";
            echo "- 付款金额: " . ($order['pay_amount'] ?? 'N/A') . "\n";
            echo "- 预计利润: " . ($order['profit'] ?? 'N/A') . "\n";
        }
    }
    
} catch (Exception $e) {
    echo "错误: " . $e->getMessage() . "\n";
    echo "堆栈跟踪: " . $e->getTraceAsString() . "\n";
} 